<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="合作媒体" prop="signatory">
        <el-select v-model="queryParams.signatory" placeholder="请选择合作媒体" clearable>
          <el-option
            v-for="dict in dict.type.medium"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="账户ID" prop="accountId">
        <el-input
          v-model="queryParams.accountId"
          placeholder="请输入账户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账户名称" prop="accountName">
        <el-input
          v-model="queryParams.accountName"
          placeholder="请输入账户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="公司名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入公司名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="未填筛选">
        <el-select v-model="queryParams.isNullList" placeholder="请选择是否显示为空信息" clearable>
          <el-option
            v-for="item in isNullLists"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['baseMain:account:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['baseMain:account:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['baseMain:account:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['baseMain:account:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="batchSingle"
          @click="handlebatchUpdate"
          v-hasPermi="['baseMain:account:edit']"
        >批量修改</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>

    </el-row>

    <el-table v-loading="loading" :data="accountList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="开户日期" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="业务部门" align="center" prop="businessUnitName" />
      <el-table-column label="销售" align="center" prop="saleUserName" />
      <el-table-column label="客户简称" align="center" prop="customName" />
      <el-table-column label="主合同" align="center" prop="mainParty" />
      <el-table-column label="甲方主体" align="center" prop="aparty" />
      <el-table-column label="账户ID" align="center" prop="accountId" />
      <el-table-column label="账户名称" align="center" prop="accountName" />
      <el-table-column label="公司名称" align="center" prop="companyName" />
      <el-table-column label="行业类型" align="center" prop="industryType" />

      <el-table-column label="合作媒体" align="center" prop="signatory">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.medium" :value="scope.row.signatory"/>
        </template>
      </el-table-column>

      <el-table-column label="开户标签" align="center" prop="accountTag" />
      <el-table-column label="帐户归属" align="center" prop="accountBelong" />

      <el-table-column label="政策类别" align="center" prop="bidding" />
      <el-table-column label="转户日期" align="center" prop="trunDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.trunDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="转入端口" align="center" prop="supplierId" />
      <el-table-column label="账显返点" align="center" prop="point" />

      <el-table-column width="180px" label="操作"  fixed="right"  align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['baseMain:account:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['baseMain:account:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改开户总表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

      <el-row>
        <el-col :span="12">

          <el-form-item label="账户归属" prop="accountBelong">
            <el-input v-model="form.accountBelong" placeholder="请输入账户归属" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="开户日期" prop="createDate">
            <el-date-picker style="width: 100%" clearable
                            v-model="form.createDate"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="请选择开户日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>

<!--        <el-row v-if="form.signatory == '巨量千川'">-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="店铺ID" prop="shopId">-->
<!--              <el-input v-model="form.shopId" placeholder="请输入店铺ID" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="店铺名称" prop="shopName">-->
<!--              <el-input v-model="form.shopName" placeholder="请输入店铺名称" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->

      <el-row>
        <el-col :span="12">

          <el-form-item label="账户ID" prop="accountId">
            <el-input v-model="form.accountId" placeholder="请输入账户ID" />
          </el-form-item>

        </el-col>
        <el-col :span="12">
          <el-form-item label="账户名称" prop="accountName">
            <el-input v-model="form.accountName" placeholder="请输入账户名称" />
          </el-form-item>
        </el-col>
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item label="公司名称" prop="companyName">
            <el-input v-model="form.companyName" placeholder="请输入公司名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">

          <el-form-item label="行业类型" prop="industryType">
            <el-input v-model="form.industryType" placeholder="请输入行业类型" />
          </el-form-item>
        </el-col>
      </el-row>




        <el-row>
          <el-col :span="12">
            <el-form-item label="转入端口" prop="supplierId">
              <el-input v-model="form.supplierId" placeholder="请输入转入端口" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="转户日期" prop="trunDate">
              <el-date-picker clearable
                              style="width: 100%"
                              v-model="form.trunDate"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="请选择转户日期">
              </el-date-picker>
            </el-form-item>

          </el-col>

        </el-row>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="24">
            <el-form-item label="业务部门" prop="businessUnitName">
              <el-tree
                class="tree-border"
                :data="deptOptions"
                highlight-current
                default-expand-all
                ref="dept"
                node-key="id"
                :current-node-key="businessUnitId"
                @node-click="getCurrentNode"
                :default-checked-keys="[form.businessUnitName]"
                :check-strictly="!form.businessUnitName"
                empty-text="加载中，请稍候"
                :props="defaultProps"
              ></el-tree>
            </el-form-item>

          </el-col>

        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="销售人员" prop="saleUserName" >
              <el-select style="width: 100%"  @change="saleUserChang(form.saleUserName)" v-model="form.saleUserName" placeholder="请选择销售人员" clearable>
                <el-option
                  v-for="sale in saleList"
                  :key="sale.userId"
                  :label="sale.nickName"
                  :value="sale.nickName"
                ></el-option>
              </el-select>
            </el-form-item>

            </el-col>

          <el-col :span="12">
            <el-form-item label="甲方主体"  prop="nickName">
              <el-select @change="changeAparty" v-model="form.aparty" style="width: 100%" filterable placeholder="请选择甲方主体" clearable>
                <el-option
                  v-if="item.aparty!=null && item.aparty!=''"
                  v-for="item in alist"
                  :key="item.id"
                  :label="item.aparty"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="12">
            <el-form-item label="合作媒体" prop="signatory">
              <el-select filterable @change="signatoryChang(form.signatory)" style="width: 100%" v-model="form.signatory" placeholder="请选择合作媒体">
                <el-option
                  v-for="dict in dict.type.medium"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>


            </el-form-item>


          </el-col>
          <el-col :span="12">
            <el-form-item label="开户标签" v-if="form.signatory!=undefined && form.signatory!='' && form.signatory.includes('巨量')" prop="accountTag">
              <el-select @change="pointCount"  v-model="form.accountTag" style="width: 100%"  placeholder="请选择开户标签">
                <el-option
                  v-for="dict in dict.type.policy_tag"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="12">

            <el-form-item label="客户简称" prop="customName">
              <el-input v-model="form.customName" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="政策类别" prop="bidding">
              <el-select v-if="signatoryFlag != '腾讯广告'" clearable @change="apartyChang()" style="width: 100%" v-model="form.biddingId" filterable placeholder="请选择政策类别">
                <el-option
                  v-for="item in biddings"
                  :key="item.id"
                  :label="item.policyType"
                  :value="item.id">
                </el-option>
              </el-select>
              <el-input v-else v-model="form.biddingId" @change="apartyInputChang()" placeholder="请输入政策类别" />
            </el-form-item>
          </el-col>
        </el-row>



        <el-row>
          <el-col :span="12">
            <el-form-item label="账显返点" prop="point">
              <el-input v-model="form.point" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主合同" prop="mainParty">
              <el-input v-model="form.mainParty" disabled/>
            </el-form-item>
          </el-col>
        </el-row>


        <el-divider></el-divider>
      <el-row>
        <el-col :span="24">

          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
          </el-form-item>
        </el-col>
      </el-row>


      <el-row>
        <el-col :span="12">

        </el-col>
        <el-col :span="12">

        </el-col>
      </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">

          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>


    <!--    批量修改对话框-->
    <el-dialog title="批量修改对话框" :visible.sync="batchopen" width="800px" append-to-body>


      <el-form ref="form" :model="batchform" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="业务部门" prop="businessUnitName">
              <el-tree
                class="tree-border"
                :data="deptOptions"
                :highlight-current="true"
                default-expand-all
                ref="dept"
                node-key="id"
                @node-click="getBatchCurrentNode"
                :default-checked-keys="[batchform.businessUnitName]"
                :check-strictly="!batchform.businessUnitName"
                empty-text="加载中，请稍候"
                :props="defaultProps"
              ></el-tree>
            </el-form-item>

          </el-col>

        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="销售人员" prop="saleUserName">
              <el-select style="width: 100%"  @change="saleUserBatchChang(batchform.saleUserName)" v-model="batchform.saleUserName" placeholder="请选择销售人员" clearable>
                <el-option
                  v-for="sale in saleList"
                  :key="sale.userId"
                  :label="sale.nickName"
                  :value="sale.nickName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="甲方主体"  prop="nickName">
              <el-select @change="changeBatchAparty" v-model="batchform.aparty" style="width: 100%" filterable placeholder="请选择甲方主体" clearable>
                <el-option
                  v-if="item.aparty!=null && item.aparty!=''"
                  v-for="item in alist"
                  :key="item.id"
                  :label="item.aparty"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>



        <el-row>
          <el-col :span="12">
            <el-form-item label="客户简称" prop="customName">
              <el-input v-model="batchform.customName" disabled/>
            </el-form-item>
          </el-col>
            <el-col :span="12">
              <el-form-item label="政策类别" prop="bidding">
                <el-select clearable @change="apartybatchChang()" style="width: 100%" v-model="batchform.biddingId" filterable placeholder="请选择政策类别">
                  <el-option
                    v-for="item in biddings"
                    :key="item.id"
                    :label="item.policyType"
                    :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>

          </el-col>

        </el-row>



        <el-row>
          <el-col :span="12">
            <el-form-item label="开户标签" prop="accountTag">
              <el-select  v-model="batchform.accountTag" style="width: 100%"  placeholder="请选择开户标签">
                <el-option
                  v-for="dict in dict.type.policy_tag"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主合同" prop="customName">
              <el-input v-model="batchform.mainParty" disabled/>
            </el-form-item>
          </el-col>
        </el-row>



        <el-divider></el-divider>
        <el-row>
          <el-col :span="24">

            <el-form-item label="备注" prop="remark">
              <el-input v-model="batchform.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitbatchForm">确 定</el-button>
        <el-button @click="batchCancel">取 消</el-button>
      </div>
    </el-dialog>


  </div>

</template>

<script>
import { listAccount, getAccount, delAccount, addAccount, updateAccount, batchEdit } from "@/api/baseMain/account";
import { getCustomList ,getCustomNames} from "@/api/baseMain/custom";
import { getListNoPages } from "@/api/baseMain/policy";
import { deptTreeSelect } from "@/api/system/role";
import { getToken } from "@/utils/auth";
import {selectUserIdsByDeptId} from "@/api/system/user";

export default {
  name: "Account",
  dicts: ['medium','policy_tag'],
  data() {
    return {
      businessUnitId: undefined,
      isNullLists:[
        {
          label:'客户简称为空',
          value:'0'
        },
        {
          label:'业务部门为空',
          value:'1'
        },
        {
          label:'两项均为空',
          value:'2'
        },
        {
          label:'两项均不为空',
          value:'3'
        }
      ],
      // 部门列表
      deptOptions: [],
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      signatoryFlag:'',
      // 非单个禁用
      single: true,
      batchSingle: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 开户总表表格数据
      accountList: [],
      customList: [],
      saleList: [],
      contractList: [],
      alist: [],
      apartys: [],
      biddings: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      batchopen: false,
      // 导入参数
      upload: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/baseMain/account/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createDate: undefined,
        accountId: undefined,
        accountName: undefined,
        companyName: undefined,
        industryType: undefined,
        shopId: undefined,
        shopName: undefined,
        accountBelong: undefined,
        contractName: undefined,
        customId: undefined,
        isNullList: undefined,
        customName: undefined,
      },
      // 表单参数
      form: {
        biddingId:undefined
      },
      batchform:{},
      // 表单校验
      rules: {
        accountId: [
          { required: true, message: "帐户ID不能为空", trigger: "blur" }
        ],
        accountName: [
          { required: true, message: "帐户名称不能为空", trigger: "blur" }
        ],
        companyName: [
          { required: true, message: "公司名称不能为空", trigger: "blur" }
        ],
        signatory: [
          { required: true, message: "合作媒体不能为空", trigger: "blur" }
        ],
        businessUnitName: [
          { required: true, message: "业务部门不能为空", trigger: "blur" }
        ],
        saleUserName: [
          { required: true, message: "销售人员不能为空", trigger: "blur" }
        ],
        accountTag: [
          { required: true, message: "开户标签不能为空", trigger: "blur" }
        ],
        // companyName: [
        //   { required: true, message: "公司名称不能为空", trigger: "blur" }
        // ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    pointCount(){
      console.log('开始匹配返点')
      //计算帐显返点
      if(!this.form.aparty){
        console.log('开始匹配返点1')
       return
      }
      if(!this.form.signatory){
        console.log('开始匹配返点2')
        return
      }
      if(!this.form.bidding){
        console.log('开始匹配返点3')
        return
      }
      if(!this.form.accountTag){
        console.log('开始匹配返点4')
        return
      }
      if(!this.form.customName){
        console.log('开始匹配返点5')
        return
      }
      console.log(this.form.aparty,this.form.signatory,this.form.bidding,this.form.accountTag);

      getListNoPages({nickName:this.form.customName,aparty:this.form.aparty,signatory:this.form.signatory,policyType:this.form.bidding,policyTag:this.form.accountTag}).then(response => {
          console.log(response);
          if(response.length > 0){
            this.form.point = response[0].accountPoint
          }
      })
    },
    changeBatchAparty(e){
      this.batchform.aparty = e.aparty
      this.batchform.customName = e.nickName
      this.batchform.saleUserName = e.saleUserName
      this.batchform.bparty = e.bparty
      this.batchform.payType = e.payType
      this.batchform.mainParty = e.mainParty
      this.batchform.customId = e.customId

      this.apartybatchChang()
    },
    saleUserChang(e){
      for (let index in this.saleList){
        if(this.saleList[index].userId == e){
          this.form.saleUserName = this.saleList[index].nickName
        }
      }
      if(this.form.saleUserName){
        //根据选择的销售人员查询对应的甲方主体
        getCustomList({saleUserName:this.form.saleUserName}).then(res=>{
          this.alist = res
        })
      }else {
        this.alist = []
        this.form.aparty = ''
        this.form.customName = ''
      }

    },
    saleUserBatchChang(e){
      for (let index in this.saleList){
        if(this.saleList[index].userId == e){
          this.batchform.saleUserName = this.saleList[index].nickName
        }
      }
      if(this.batchform.saleUserName){
        //根据选择的销售人员查询对应的甲方主体
        getCustomList({saleUserName:this.batchform.saleUserName}).then(res=>{
          this.alist = res
        })
      }else {
        this.alist = []
        this.batchform.aparty = ''
        this.batchform.customName = ''
      }

    },
    changeAparty(e){
      this.form.aparty = e.aparty
      this.form.customName = e.nickName
      this.form.saleUserName = e.saleUserName
      this.form.cooperateType = e.cooperateType
      this.form.bparty = e.bparty
      this.form.mainParty = e.mainParty
      this.form.customId = e.customId

      this.apartyChang()
      this.pointCount()
    },
    getCurrentNode(e){
      this.form.businessUnit = e.id
      this.form.businessUnitName = e.label


      let sale = {
        roleId : '1741717661796728834',
        deptId : e.id
      }
      // 查询销售人员
      selectUserIdsByDeptId(sale).then(response =>{
        this.saleList = response.data
        if(this.saleList.length == 0){
          this.form.saleUserName = null
          this.form.saleUser = null
        }
      })
    },
    getBatchCurrentNode(e){
      this.batchform.businessUnit = e.id
      this.batchform.businessUnitName = e.label

      let sale = {
        roleId : '1741717661796728834',
        deptId : e.id
      }
      // 查询销售人员
      selectUserIdsByDeptId(sale).then(response =>{
        this.saleList = response.data
        if(this.saleList.length == 0){
          this.form.saleUserName = null
          this.form.saleUser = null
        }
      })
    },
    /** 根据角色ID查询部门树结构 */
    getDeptTree() {
      return deptTreeSelect(1).then(response => {
        this.deptOptions = response.data.depts;
        return response;
      });
    },
    apartybatchChang(){
      getListNoPages({nickName:this.batchform.customName}).then(res =>{
        this.biddings = res
        for(let index in this.biddings){
          if(this.batchform.biddingId == this.biddings[index].id){
            this.batchform.bidding = this.biddings[index].policyType
          }

        }
      })
    },
    apartyInputChang(){
      this.form.bidding =   this.form.biddingId
      this.pointCount()
    },
    apartyChang(){
      getListNoPages({nickName:this.form.customName}).then(res =>{
        this.biddings = res
        for(let index in this.biddings){
          if(this.form.biddingId == this.biddings[index].id){
            this.form.bidding = this.biddings[index].policyType
          }

        }
      })
      this.pointCount()
    },
    accountBitchBelongChang(e){
      this.batchform.bidding=''
      this.batchform.biddingId=''
      getListNoPages({nickName:this.batchform.customName.split("|")[0]}).then(res =>{
        this.biddings = res
        for(let index in this.biddings){
          if(this.batchform.biddingId == this.biddings[index].id){
            this.batchform.bidding = this.biddings[index].policyType
          }

        }
      })
      this.batchform.customName=e.split('|')[0]
      this.batchform.saleUserName=e.split('|')[1]
    },
    accountBelongChang(e){
      console.log(e)
      this.form.saleUserName=''
      this.form.bidding=''
      this.form.biddingId=''
      getListNoPages({nickName:this.form.customName.split("|")[0]}).then(res =>{
        this.biddings = res
        for(let index in this.biddings){
          if(this.form.biddingId == this.biddings[index].id){
            this.form.bidding = this.biddings[index].policyType
          }

        }
      })
      this.form.customName=e.split('|')[0]
      this.form.saleUserName=e.split('|')[1]
    },
    signatoryChang(e){
        this.signatoryFlag = e
      if(e != '巨量千川' ){
        this.form.shopId = null
        this.form.shopName = null
      }
      // if(this.form.signatory!=undefined && this.form.signatory!='' && this.form.signatory.includes('巨量')){
      //   this.form.accountTag = undefined
      // }

      this.pointCount()
    },
    getCustomList(){
      getCustomList().then(response => {
        this.customList = response;
      });
    },
    /** 查询开户总表列表 */
    getList() {
      this.loading = true;
      listAccount(this.queryParams).then(response => {
        this.accountList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 批量取消按钮
    batchCancel() {
      this.batchopen = false;
      this.reset();
    },
    // 批量表单重置
    batchReset() {
      this.batchform = {
        id: undefined,
        createDate: undefined,
        accountId: undefined,
        accountName: undefined,
        companyName: undefined,
        industryType: undefined,
        shopId: undefined,
        shopName: undefined,
        accountBelong: undefined,
        contractName: undefined,
        customId: undefined,
        customName: undefined,
        businessUnit: undefined,
        bidding: undefined,
        biddingId: undefined,
        point: undefined,
        trunDate: undefined,
        supplierId: undefined,
        remark: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        isNullList: undefined,
        accountTag: undefined,
        aparty: undefined,
        updateBy: undefined
      };
      this.resetForm("batchform");
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        createDate: undefined,
        accountId: undefined,
        accountName: undefined,
        companyName: undefined,
        industryType: undefined,
        shopId: undefined,
        shopName: undefined,
        accountBelong: undefined,
        contractName: undefined,
        customId: undefined,
        customName: undefined,
        businessUnit: undefined,
        bidding: undefined,
        biddingId: undefined,
        point: undefined,
        trunDate: undefined,
        supplierId: undefined,
        remark: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        isNullList: undefined,
        updateBy: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.isNullList = undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.batchSingle = selection.length<1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加开户信息";
      this.getCustomList()
      this.getDeptTree();
    },
    /**批量修改按钮*/

    handlebatchUpdate(row) {
      this.getDeptTree();
      this.reset();
      const id = row.id || this.ids
      this.batchopen = true;
      this.getCustomList()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.getDeptTree();
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getAccount(id).then(response => {
        this.form = response.data;
        this.loading = false;
        this.businessUnitId = response.data.businessUnit;
        this.open = true;
        this.title = "修改开户信息";
        this.$nextTick(() => {
          this.$refs['dept'].setCurrentKey(this.businessUnitId);
        });
        this.getCustomList()


      });
    },
    /** 提交按钮 确认 */
    submitForm() {
      // 返点预设值
      // if(Math.abs(this.form.point - this.point).toFixed(2)>1){
      //   this.$modal.confirm('返点值已超过预设标准，请确认后保存').then(() => {
      //   }).then(() => {
      //     this.submitEnd()
      //   }).catch(() => {
      //   }).finally(() => {
      //
      //   });
      // }else{
        this.submitEnd()
      // }
    },
    submitbatchForm(){
      this.batchform.ids = this.ids

      batchEdit(this.batchform).then(res =>{
        this.$modal.msgSuccess("批量修改成功");
        this.batchopen = false;
        this.getList();
      })
    },
    submitEnd(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateAccount(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addAccount(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除开户信息编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delAccount(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('baseMain/account/export', {
        ...this.queryParams
      }, `account_${new Date().getTime()}.xlsx`)
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "数据导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('baseMain/account/importTemplate', {
      }, `account_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }

  }
};
</script>
